/*
 * Project: purple
 * 
 * File Created at 2018年12月8日
 * 
 */
package xin.mydreams.purple.constant.req;

import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import io.netty.handler.codec.http.DefaultHttpRequest;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.QueryStringDecoder;
import lombok.Data;
import xin.mydreams.purple.constant.param.ParamMap;

/**
 * HTTP请求
 * 
 * @Type PurpleHttpRequest.java
 * @email guzehao@mydreams.xin
 * @author 谷泽昊
 * @blog https://www.mydreams.xin
 * @date 2018年12月8日 上午11:23:34
 * @version
 */
@Data
public class PurpleHttpRequest {

	private String uri;

	private String path;

	private ParamMap paramMap=new ParamMap();

	private HttpMethod method;
	private HttpHeaders headers;

	public PurpleHttpRequest(DefaultHttpRequest httpRequest) {
		this.uri = httpRequest.uri();
		QueryStringDecoder queryStringDecoder = new QueryStringDecoder(this.uri);
		this.path=queryStringDecoder.path();
		Map<String, List<String>> map = queryStringDecoder.parameters();
		Set<Entry<String, List<String>>> entrySet = map.entrySet();
		for (Entry<String, List<String>> entry : entrySet) {
			List<String> list = entry.getValue();
			if (list != null && list.size() > 0) {
				paramMap.put(entry.getKey(), list.get(0));
			}
		}
		this.method = httpRequest.method();
		this.headers = httpRequest.headers();
	}

}

/**
 *
 * Revision history
 * -------------------------------------------------------------------------
 * 
 * Date Author Note
 * -------------------------------------------------------------------------
 * 2018年12月8日 谷泽昊 creat
 */